package com.djl.Zookeeper.lock;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;

public class TestLock {

    public static void main(String[] args) throws IOException {

        for (int i = 1; i <50; i++) {
            new Thread(()->{

                //创建分布式锁管理对象
                ZkLock zkLock = new ZkLock();

                //尝试获取锁
                zkLock.tryLock();

                //干事
                System.out.println(Thread.currentThread().getName()+" 获取锁!");

                //释放锁
                try {
                    zkLock.unLock();
                } catch (KeeperException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }

}
